package work20241224;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author zdl
 * @date 2024/12/24
 */
interface A {
    void eat();
}

interface B {
    void eat(int n);
}

interface C {
    void sleep(int a, int b);
}

interface D {
    int add(int a, int b);
}

public class Demo3 {
    public static void main(String[] args) {
        /*new Thread(() -> System.out.println("打印")).start();
        new Thread(() -> System.out.println("hhhh")).start();
        new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                System.out.println("线程："+Thread.currentThread().getName());
            }
        }) .start();*/
        test1(() -> System.out.println("吃饭了!"));
        test2(n -> System.out.println(n), 10);
        test2(System.out::println, 5);
        test3((a, b) -> System.out.println(a + b), 2, 5);
        test4((a, b) ->  a + b, 3, 4);

        //线程池
        ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(5, 10, 20, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(10));
        poolExecutor.execute(() -> {
            for (int i = 0; i < 10; i++) {
                System.out.println(Thread.currentThread().getName()+"执行");
            }
        });

        //ArrayList集合
        ArrayList<Integer> list = new ArrayList<>();
        list.add(5);
        list.add(3);
        list.add(2);
        list.add(4);
        System.out.println(list);
        Collections.sort(list, (o1,o2) ->  o2 - o1);
        System.out.println(list);
    }

    public static void test1(A a) {
        a.eat();
    }

    public static void test2(B b, int n) {
        b.eat(n);
    }

    public static void test3(C c, int a, int b) {
        c.sleep(a, b);
    }

    public static void test4(D d, int a, int b) {
        d.add(a, b);
    }
}
